package com.glodon.paas.monitor.server.exposed.receiver;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.glodon.paas.monitor.server.biz.service.MonitorStatusService;


@Component
public class MonitorEventListener implements MessageListener {

	private static final Logger		logger	= LoggerFactory.getLogger(MonitorEventListener.class);

	@Autowired
	private MonitorStatusService	monitorStatusService;

	@Override
	public void onMessage(Message message) {
		if (message instanceof TextMessage) {
			TextMessage textMessage = (TextMessage) message;
			try {
				monitorStatusService.processMesage(textMessage);
			} catch (JMSException e) {
				logger.error("process monitor event failure, message: {}", message, e);
			}
		} else {
			logger.warn("receive monitor event message, but is not text message, message: {}", message);
		}
	}

}
